package com.dexilaonian.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dexilaonian.R;
import com.dexilaonian.utils.Constant;
import com.dexilaonian.utils.Okhttp;
import com.dexilaonian.utils.PreferencesUtil;

public class DecsunActivity extends AppCompatActivity {

    private WebView decsun_web;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_decsun);
        decsun_web = (WebView) findViewById(R.id.decsun_web);
        initData();
    }


    private void initData() {
        WebSettings webSettings = decsun_web.getSettings();
        // 让WebView能够执行javaScript
        webSettings.setJavaScriptEnabled(true);
        // 让JavaScript可以自动打开windows
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        // 设置缓存
        webSettings.setAppCacheEnabled(true);
        // 设置缓存模式,一共有四种模式
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        // 设置缓存路径
//        webSettings.setAppCachePath("");
        // 支持缩放(适配到当前屏幕)
        webSettings.setSupportZoom(true);
        // 将图片调整到合适的大小
        webSettings.setUseWideViewPort(true);
        // 支持内容重新布局,一共有四种方式
        // 默认的是NARROW_COLUMNS
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        // 设置可以被显示的屏幕控制
        webSettings.setDisplayZoomControls(true);
        // 设置默认字体大小
        webSettings.setDefaultFontSize(12);
        url = "http://www.decsungroup.com/";
     /*   if (!TextUtils.isEmpty(PreferencesUtil.getString(DecsunActivity.this, Constant.KEY))) {
            url2 = url + "?token=" + PreferencesUtil.getString(DecsunActivity.this, Constant.KEY);
        }*/
        // 设置WebView的客户端
        decsun_web.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;// 返回false
            }
        });
        decsun_web.loadUrl(url);
    }
    @Override
    public void onBackPressed() {
        if (decsun_web.canGoBack()) {
            if (decsun_web.getUrl().equals(url)) {
                super.onBackPressed();
            } else {
                decsun_web.goBack();
            }
        } else {
            super.onBackPressed();
        }
    }
}
